package org.yty.travelagencyredis.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.yty.travelagencyredis.model.Entity.ChatGroup;
import org.yty.travelagencyredis.model.Entity.Result;
import org.yty.travelagencyredis.model.VO.ChatGroupQueryVO;
import org.yty.travelagencyredis.service.ChatGroupService;

@RestController
@RequestMapping("/chat-group")
@RequiredArgsConstructor
public class ChatGroupController {
    private final ChatGroupService chatGroupService;

    @GetMapping("/{id}")
    public Result<ChatGroupQueryVO> getChatGroupById(@PathVariable String id) {
        ChatGroupQueryVO result = this.chatGroupService.getById(id);
        if (result == null){
            return Result.error("暂无数据");
        }
        return Result.ok(result);
    }

    @PostMapping
    public Result<Void> save(@RequestBody ChatGroup chatGroup) {
        boolean result = this.chatGroupService.save(chatGroup);
        if (!result){
            return Result.error("保存失败");
        }
        return Result.ok();
    }

    @PutMapping
    public Result<Void> update(@RequestBody ChatGroup chatGroup) {
        boolean result = this.chatGroupService.update(chatGroup);
        if (!result){
            return Result.error("更新失败");
        }
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteById(@PathVariable String id){
        this.chatGroupService.deleteById(id);
        return Result.ok();
    }
}
